package xiaodou.modules.workBar.data
{
	import flash.events.EventDispatcher;
	
	import xiaodou.modules.workBar.events.DelayWeiboEvent;

	public class WorkBarModel extends EventDispatcher
	{
		private var _delayNewWeiboArr:Array;
		
		private var _delayReplyArr:Array;
		
		private var _delayCommentReplyArr:Array;
		
		public function WorkBarModel()
		{
			_delayNewWeiboArr = new Array();
			_delayReplyArr = new Array();
			_delayCommentReplyArr = new Array();
		}
		
		/**
		 *  
		 * @param delayWeiboDataArr
		 * 
		 */		
		public function addDelayWeibo(delayWeiboDataArr:Array):void
		{
			for each(var weibo:DelayWeiboData in delayWeiboDataArr)
			{
				if(weibo.weiboId == "0")
					_delayNewWeiboArr.push(weibo);
				else if(weibo.commentId == null || weibo.commentId.length == 0)
					_delayReplyArr.push(weibo);
				else
					_delayCommentReplyArr.push(weibo);
			}
			dispatchEvent(new DelayWeiboEvent(DelayWeiboEvent.DELAY_WEIBO_LIST_RECEIVED));
		}
		
		public function removeDelayWeibo(weibo:DelayWeiboData):void
		{
			var arr:Array;
			if(weibo.weiboId == "0")
				arr = _delayNewWeiboArr;
			else if(weibo.commentId == null || weibo.commentId.length == 0)
				arr = _delayReplyArr;
			else
				arr =_delayCommentReplyArr;
			for (var i:int = 0; i < arr.length; i++) 
			{
				var temp:DelayWeiboData = arr[i];
				if(temp.id == weibo.id)
				{
					arr.splice(i, 1);
					break;
				}
			}
			dispatchEvent(new DelayWeiboEvent(DelayWeiboEvent.DELAY_WEIBO_DELETE_RECEIVED));
			
		}
		
		public function updateDelayWeibo(data:Object):void
		{
			var newWeibo:DelayWeiboData = new DelayWeiboData();
			newWeibo.fill(data);
			var arr:Array;
			if(newWeibo.weiboId == "0")
				arr = _delayNewWeiboArr;
			else if(newWeibo.commentId == null || newWeibo.commentId.length == 0)
				arr = _delayReplyArr;
			else
				arr =_delayCommentReplyArr;
			for (var i:int = 0; i < arr.length; i++) 
			{
				var temp:DelayWeiboData = arr[i];
				if(temp.id == newWeibo.id)
				{
					temp.fill(data);
					dispatchEvent(new DelayWeiboEvent(DelayWeiboEvent.DELAY_WEIBO_UPDATE_RECEIVED, temp));
					break;
				}
			}
		}
		
		public function clear():void
		{
			_delayNewWeiboArr.splice(0);
			_delayReplyArr.splice(0);
			_delayCommentReplyArr.splice(0);
		}

		/**
		 * 定时发送的新微博 
		 */
		public function get delayNewWeiboArr():Array
		{
			return _delayNewWeiboArr;
		}

		/**
		 * 定时发送的对微博的评论 
		 */
		public function get delayReplyArr():Array
		{
			return _delayReplyArr;
		}

		/**
		 * 定时发送的对评论的评论 
		 */
		public function get delayCommentReplyArr():Array
		{
			return _delayCommentReplyArr;
		}


	}
}